package com.mihu.stmall.front.mapper;

import com.mihu.stmall.front.entity.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {

    //只查询一级分类
    //parentId空
    @Select({"select * from category" ,
    "where parent_id is null",
            "and status=0",
    })
    @Results({
            @Result(column = "id",property = "id",id = true),
            @Result(column = "id",property ="children",
            many = @Many(select="selectByParentId"))
    })
    List<Category> selectParent();

    //根据父分类查询

    @Select({"select * from category",
    "where parent_id=#{parentId}",
            "and status=0",
    })
    List<Category> selectByParentId(Integer parentId);
}
